package com.nbsaas.boot.vipcard.rest.convert;

import com.nbsaas.boot.vipcard.data.entity.VipCard;
import com.nbsaas.boot.vipcard.api.domain.request.VipCardRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.jpa.data.entity.User;
            import com.nbsaas.boot.vipcard.data.entity.VipCardTemplate;

/**
* 请求对象转换成实体对象
*/

public class VipCardEntityConvert  implements Converter<VipCard, VipCardRequest> {

    @Override
    public VipCard convert(VipCardRequest source) {
        VipCard result = new VipCard();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getOwner()!=null){
                    User owner =new User();
                    owner.setId(source.getOwner());
                    result.setOwner(owner);
                    }
                    if(source.getCard()!=null){
                    VipCardTemplate card =new VipCardTemplate();
                    card.setId(source.getCard());
                    result.setCard(card);
                    }
        return result;
    }
}

